<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<%@include file="/WEB-INF/jspf/meta/meta.jspf"%>
<title>教师信息列表</title>
<%@include file="/WEB-INF/jspf/adminPage.jspf"%>
</head>
<body>
	
		<table class="easyui-datagrid" id="dg_Teacher" title="宿舍信息列表"
			data-options="fit:true,fitColumns:true,singleSelect:false,pagination:true,collapsible:true,toolbar:'#tb',url:'<%=request.getContextPath()%>/teacher/TeacherList.json?',method:'get'">
			<thead>
				<tr>
					<th field="ck" checkbox="true"></th>
					<th data-options="field:'teacherId',width:80,aling:'center'">教师编号</th>
					<th data-options="field:'teacherName',width:100,aling:'center'">教师姓名</th>
					<th data-options="field:'teacherBirthday',width:100,aling:'center'">教师生日</th>
					<th data-options="field:'teacherPhone',width:100,aling:'center'">教师电话</th>
					<th data-options="field:'teacherAddr',width:100,aling:'center'">教师地址</th>
					<th data-options="field:'teacherSex',width:100,aling:'center'">教师性别</th>
					<th data-options="field:'teacherEmail',width:100,aling:'center'">教师邮箱</th>
					<th data-options="field:'teacherAccount',width:100,aling:'center'">教师账号</th>
					<th data-options="field:'teacherPassword',width:100,aling:'center'">教师密码</th>
					<th
						data-options="field:'teacherStartdate',width:100,aling:'center'">教师入职日期</th>
					<th data-options="field:'teacherEnddate',width:100,aling:'center'">教师离职日期</th>
					<th data-options="field:'teacherSytle',width:250,aling:'center'">状态</th>

				</tr>
			</thead>
		</table>
	<div id="tb">
		<div>
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
				onclick="addTea()">添加</a> <a href="#" class="easyui-linkbutton"
				iconCls="icon-edit" plain="true" onclick="updateTea()">修改</a> <a
				href="#" class="easyui-linkbutton" iconCls="icon-remove"
				plain="true" onclick="deleteTeacher()">删除</a>
		</div>
		<div style="text-align: center;" >
			教师状态：<select  class="easyui-combobox" id="t_style" name="style"  data-options="editable:false"
							style="width: 100px;">
								
								<option value="离职" >离职</option>
								<option value="在职"  >在职</option>
								<option value="" selected="selected" >所有</option>
					</select> 
			教师名称：<input type="text" id="findName" value="" name="findName" style="width: 100px" /> <a href="javascript:void(0)"
				class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="forLike()">查询</a> &nbsp;&nbsp;<a href="javascript:void(0)" onclick="dowan()">导出Excel数据</a>
				&nbsp;&nbsp;<form id="upfile" action="<%=request.getContextPath()%>/teacher/upload.json" method="post" enctype="multipart/form-data" style="display: inline;" onsubmit="return check()">
						<input id="file" name="file" type="file" style="width: 170px" /><input type="submit" value="导入Excel数据"/>
				</form>
		</div>
	</div>
	<!-- 引入添加页面 -->
	<%@ include file="/WEB-INF/jsp/teacher/listForAdd.jspf" %>
	<!-- 引入修改页面 -->
	<%@ include file="/WEB-INF/jsp/teacher/listForUpdate.jspf" %>
		<script type="text/javascript">
		
		function check(){
			if($('#file').val()==null||$('#file').val()==''){
				alert("请选择需要上传的Excel文件！")
				return false;
			}
			return true;
		}
			
		//根据姓名重新向后台请求数据，表跟根据返回的data生成数据
		function forLike(){
			var name=$('#findName').val()
			var style=$('#t_style option:selected').val()
			   $.ajax({
		            url : "<%=request.getContextPath()%>/teacher/TeacherList.json?style="+style+"&findName="+name
		            ,success : function(data) {
		                $("#dg_Teacher").datagrid("loadData", data.rows); //动态取数据
		            }
		        });
		}
		//添加方法
		function addTea() {
			$('#win_Teacheradd').window('open')
		}
		//修改方法
		function updateTea() {
			var rows=$('#dg_Teacher').datagrid('getChecked')
			if(rows.length==0){
				$.messager.show({
					title:'操作提示',
					msg:'请选择需要操作的数据',
					timeout:3000,
					showType:'slide'
				});
				return;
			}else if(rows.length>1){
				$.messager.show({
					title:'操作提示',
					msg:'请选择一条需要操作的数据进行操作',
					timeout:3000,
					showType:'slide'
				});
				return;
			}
			$('#ff_teacherUpdate').form('load','<%=request.getContextPath()%>/teacher/dataForm.json?tid='+rows[0].teacherId)
			$('#win_Teacherupdate').window('open')
		}
		
		//批量删除方法
		function deleteTeacher(){
			var rows=$('#dg_Teacher').datagrid('getChecked')
			if(rows.length==0){
				$.messager.show({
					title:'操作提示',
					msg:'请选择需要操作的数据进行操作',
					timeout:3000,
					showType:'slide'
				});
				return;
			}
			var tId=[];
			for (var i = 0; i < rows.length; i++) {
				tId.push(rows[i].teacherId)
			}
			 $.ajax({url:"<%=request.getContextPath()%>/teacher/deleteTeacher.json?list="+tId
				 ,success:function(data){
						$.messager.show({
							title:'操作提示',
							msg:data.msg,
							timeout:5000,
							showType:'slide'
						});
					 $('#dg_Teacher').datagrid('reload');
		    }});
		}
		function dowan(){
			var url='<%=request.getContextPath()%>/teacher/download'
			window.location=url
		}
		</script>
</body>
</html>